package br.com.projetosivan.pagamento;

import java.net.URL;
import java.util.List;

import br.com.uol.pagseguro.domain.AccountCredentials;
import br.com.uol.pagseguro.domain.Currency;
import br.com.uol.pagseguro.domain.Item;
import br.com.uol.pagseguro.domain.PaymentRequest;
import br.com.uol.pagseguro.domain.ShippingType;
import br.com.uol.pagseguro.exception.PagSeguroServiceException;

public class PagamentoHandler {
	
	
	public URL efetuarPagamento(List<Item> itens, String reference, ShippingType shipping, 
			String nomecomprador, String emailcomprador, String codigoarea, String telefone){
	    PaymentRequest paymentRequest = new PaymentRequest();  
	    
	    
	    for (int i = 0 ; i < itens.size() ; i++){
	    	paymentRequest.addItem(itens.get(i));
	    }
	    
	    paymentRequest.setCurrency(Currency.BRL);  
	
	    //Referência ao pagamento
	    paymentRequest.setReference(reference);  
	    
	    paymentRequest.setShippingType(shipping);
	    
	    //Comprador
	    paymentRequest.setSender(nomecomprador , emailcomprador, codigoarea, telefone); 
	    URL paymentURL = null;
	    try {
			 paymentURL = paymentRequest.register(new  
			    AccountCredentials(  
			        "ivanjunckes@gmail.com",   
			        "B04D6DD6AC1241E09A0D69D4AA22EF56")  
			    );
		} catch (PagSeguroServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
		
		return paymentURL;
	}
}
